<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('定时任务新增及修改')" />
	<style type="text/css">
        .layui-form-label {width:120px;}
        .layui-input-block {margin-left: 150px}
        .layui-form-radio {line-height: 45px;margin: 0 0;padding-right: 0;}
    </style>
</head>
<body>
<form class="layui-form" id="form-job-add" style="padding: 5px 80px 10px 80px;">
<input type="hidden" id="jobId" name="jobId"  th:value="${job?.jobId}">
<input type="hidden" id="createUser" name="createUser" th:value="${@permission.getPrincipalProperty('userName')}">
<input type="hidden" id="updateUser" name="updateUser" th:value="${@permission.getPrincipalProperty('userName')}">
	<div class="layui-form-item">
	  <label class="layui-form-label"><font class="f_red">*</font>任务名称：</label>
	  <div class="layui-input-block">
	    <input type="text" name="jobName" id="jobName" th:value="${job?.jobName}" lay-verify="required" autocomplete="off" placeholder="请输入" class="layui-input">
	  </div>
	</div>
	<div class="layui-form-item">
	  <label class="layui-form-label">任务分组：</label>
	  <div class="layui-input-block">
	  	<select name="jobGroup" id="jobGroup">
	  		<option value="DEFAULT">默认</option>
	  		<option value="SYSTEM">系统</option>
            <!-- <option th:each="fieldFrontTempletType:${fieldFrontTempletType}" th:value="${fieldFrontTempletType.key}" th:valuecn="${fieldFrontTempletType.value}" th:text="${fieldFrontTempletType.value}" th:selected="${fieldFrontTempletType.key} eq ${dictionaryForField?.fieldFrontTemplet}"></option>-->
 		</select>
	  </div>
	</div>
	<div class="layui-form-item">
	  <label class="layui-form-label"><font class="f_red">*</font>调用目标字符串：</label>
	  <div class="layui-input-block">
	    <input type="text" name="invokeTarget" id="invokeTarget" th:value="${job?.invokeTarget}" lay-verify="required" autocomplete="off" placeholder="请输入" class="layui-input">
	  	<span><i class="fa fa-info-circle"></i> Bean调用示例：ryTask.ryParams('ry')</span><br/>
	    <span><i class="fa fa-info-circle"></i> Class类调用示例：com.ruoyi.quartz.task.RyTask.ryParams('ry')</span><br/>
	    <span><i class="fa fa-info-circle"></i> 参数说明：支持字符串，布尔类型，长整型，浮点型，整型</span><br/>
	  </div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label"><font class="f_red">*</font>cron表达式：</label>
		<div class="layui-input-block">
			<input type="text" name="cronExpression" id="cronExpression" th:value="${job?.cronExpression}" lay-verify="required" autocomplete="off" placeholder="请输入" class="layui-input">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">执行策略：</label>
		<div class="layui-input-block">
			<input type="radio" name="misfirePolicy" value="1" title="立即执行" checked> 
			<input type="radio" name="misfirePolicy" value="2" title="执行一次" th:checked="${job?.misfirePolicy=='2'}">
			<input type="radio" name="misfirePolicy" value="3" title="放弃执行" th:checked="${job?.misfirePolicy=='3'}">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">并发执行：</label>
		<div class="layui-input-block">
			<input type="radio" name="concurrent" value="0" title="允许" checked>
			<input type="radio" name="concurrent" value="1" title="禁止" th:checked="${job?.concurrent=='1'}">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">状态：</label>
		<div class="layui-input-block">
			<input type="radio" name="status" value="0" title="正常" checked>
			<input type="radio" name="status" value="1" title="暂停" th:checked="${job?.status=='1'}">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">备注：</label>
		<div class="layui-input-block">
			<textarea id="remark" name="remark" class="layui-textarea" th:text="${job?.remark}" placeholder="请输入内容"></textarea>
		</div>
	</div>
</form>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
	/*<![CDATA[*/
	var prefix = ctx + "common/job";
	/*]]>*/
</script>
<script type="text/javascript">
layui.use(['table','form','layer','jquery'], function () {
    var $ = layui.$,layer = layui.layer,form = layui.form,table = layui.table;
	$("#form-job-add").validate({
		onkeyup: false,
		rules:{
			cronExpression:{
				remote: {
		            url: prefix + "/checkCronExpressionIsValid",
		            type: "post",
		            dataType: "json",
		            data: {
		                "cronExpression": function() {
		                    return $.common.trim($("#cronExpression").val());
		                }
		            },
		            dataFilter: function(data, type) {
		            	return data;
		            }
		        }
			},
		},
		messages: {
	       "cronExpression": {
	           remote: "表达式不正确，形如：0/10 * * * * ?"
	       }
	   },
	   focusCleanup: true
	});
	form.render();
});
function submitHandler() {
	if($('#jobId').val()){//通过判断jobId是否存在来判断是新增还是保存
		if ($.validate.form()) {
			$('#createUser').val('');
            $.operate.save(prefix + "/edit", $.common.formToJSON('form-job-add'));
        }
	}else{
		if ($.validate.form()) {
			$('#updateUser').val('');
	    	$.operate.save(prefix + "/add", $.common.formToJSON('form-job-add'));
	    }
	}
}
</script>
</body>
</html>
